package com.sanyang.pda.presenter;


import com.google.gson.Gson;
import com.sanyang.pda.bean.ManualDeliveryBean;
import com.sanyang.pda.bean.ManualPalletBean;
import com.sanyang.pda.bean.PageBean;
import com.sanyang.pda.contract.ManualDeliveryContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class ManualDeliveryPresenter extends BasePresenter<ManualDeliveryContract.View> implements ManualDeliveryContract.Presenter {

    @Override
    public void manualDeliveryList(int num) {
        PageBean pageBean=new PageBean(num);
        RequestBody requestBody = RequestBody.create(MediaType.parse("\"application/json;charset=UTF-8\""), new Gson().toJson(pageBean));
        NetUtils.geApi().manualDeliveryList(num,10)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<ManualDeliveryBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<ManualDeliveryBean>> listBaseRowsAppEntity) throws Exception {
                        getView().setList(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
